package com.hyjx.framework.component.operatelog;

import com.hyjx.framework.component.operatelog.operatelogdetail.OperatelogDetailModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 操作日志
 */
@Controller
@RequestMapping("/operatelog")
public class OperatelogController {
    @Resource(name = "operatelogServiceImpl")
    private OperatelogService service;

    /**
     * 进入到信息查询页面
     *
     * @return
     */
    @RequestMapping(value = "/gotoList", method = RequestMethod.GET)
    public String gotoList(HttpServletRequest request) {
        List<OperatelogModel> list = service.queryModelList(new OperatelogModel());
        request.setAttribute("oplist", list);
        OperatelogDetailModel odmodel = new OperatelogDetailModel();

        odmodel.setOlid(request.getParameter("oid"));
        if (odmodel.getOlid() != null) {
            List<OperatelogDetailModel> listdetail = service.queryDetailModelList(odmodel);
            request.setAttribute("opdlist", listdetail);
        }
        return "/framework/component/operatelog/list";
    }

    /**
     * 执行客户查询操作
     *
     * @param model
     * @param request
     * @return
     */
    @RequestMapping(value = "/queryList", method = RequestMethod.POST)
    @ResponseBody
    public String queryList(OperatelogModel model, HttpServletRequest request) {

        return service.queryList(model);
    }

    /**
     * 信息查看
     * request
     *
     * @return
     */
    @RequestMapping(value = "/gotoView", method = RequestMethod.GET)
    public ModelAndView gotoView(HttpServletRequest request) {
        String id = request.getParameter("id");
        OperatelogModel model = service.getInfoById(id);
        ModelAndView mav = new ModelAndView("/framework/component/operatelog/view");
        mav.addObject("model", model);
        return mav;
    }
}